<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Base Sprite</title>
</head>
<body>
  <canvas id="mycanvas" width="1200" height="600"></canvas>
  <!-- <script src="https://unpkg.com/sprite-core@2.26.15/dist/sprite-core.min.js"></script> -->
  <script src="/js/sprite-core.js"></script>
  <script>
    const Sprite = spritejs.Sprite;
    const Layer = spritejs.Layer;
    const Group = spritejs.Group;
    const context = document.getElementById('mycanvas').getContext('2d');
    const layer = new Layer({context});

    const g = new Group();
    g.attr({
      pos: [300, 300],
      width: 400,
      anchor: 0.5,
      bgcolor: 'grey',
      alignItems: 'stretch',
      display: 'flex',
    });

    layer.append(g);

    const s1 = new Sprite();
    s1.attr({
      size: [250, 50],
      borderRadius: 25,
      bgcolor: 'red',
      // flex: 1,
    });
    const s2 = s1.cloneNode();
    s2.attr({
      size: [50, 50],
      bgcolor: 'blue',
      flex: 2,
    });
    const s3 = s1.cloneNode();
    s3.attr({
      size: [50, 50],
      bgcolor: 'green',
      // flex: 0,
      order: -1,
    });

    const s4 = new Sprite();
    s4.attr({
      // height: 70,
      width: 30,
      borderRadius: 0,
      bgcolor: 'purple',
    });
    g.append(s1, s2, s3, s4);

    g.relayout();

    s1.animate([
      {size: [200, 100]},
      {size: [50, 50]},
    ], {
      duration: 5000,
      iterations: Infinity,
      direction: 'alternate',
    });
  </script>
</body>
</html>
